package com.ruoyi.web.controller.market.sys;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.PackageInfo;
import com.ruoyi.sys.service.IPackageInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.PackageInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 马甲包管理Controller
 * 
 * @author ruoyi
 * @date 2022-08-23
 */
@Controller
@RequestMapping("/sys/packgeInfo")
public class PackageInfoController extends BaseController
{
    private String prefix = "sys/packgeInfo";

    @Autowired
    private IPackageInfoService packageInfoService;

    @RequiresPermissions("sys:packgeInfo:view")
    @GetMapping()
    public String packgeInfo()
    {
        return prefix + "/packgeInfo";
    }

    /**
     * 查询马甲包管理列表
     */
    @RequiresPermissions("sys:packgeInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PackageInfo packageInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = packageInfoService.selectPackageInfoListMap(packageInfo);
        mapList = new PackageInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出马甲包管理列表
     */
    @RequiresPermissions("sys:packgeInfo:export")
    @Log(title = "马甲包管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PackageInfo packageInfo)
    {
        List<PackageInfo> list = packageInfoService.selectPackageInfoList(packageInfo);
        ExcelUtil<PackageInfo> util = new ExcelUtil<PackageInfo>(PackageInfo.class);
        return util.exportExcel(list, "马甲包管理数据");
    }

    /**
     * 新增马甲包管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存马甲包管理
     */
    @RequiresPermissions("sys:packgeInfo:add")
    @Log(title = "马甲包管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PackageInfo packageInfo)
    {
        return toAjax(packageInfoService.insertPackageInfo(packageInfo));
    }

    /**
     * 修改马甲包管理
     */
    @RequiresPermissions("sys:packgeInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        PackageInfo packageInfo = packageInfoService.selectPackageInfoById(id);
        mmap.put("packageInfo", packageInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存马甲包管理
     */
    @RequiresPermissions("sys:packgeInfo:edit")
    @Log(title = "马甲包管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PackageInfo packageInfo)
    {
        return toAjax(packageInfoService.updatePackageInfo(packageInfo));
    }

    /**
     * 删除马甲包管理
     */
    @RequiresPermissions("sys:packgeInfo:remove")
    @Log(title = "马甲包管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(packageInfoService.deletePackageInfoByIds(ids));
    }

    /**
     * 状态修改
     */
    @RequiresPermissions("sys:packgeInfo:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(PackageInfo packageInfo)
    {
        return toAjax(packageInfoService.updatePackageInfo(packageInfo));
    }

}
